﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.ClientApp.Book
{
    /// <summary>
    /// 预约
    /// </summary> 
    [Route("api/v1/ClientApp/[controller]")]
    [ApiExplorerSettings(GroupName = "ClientApp")]
    public class BookController : ClientAppBaseController
    {
        public BookController()
        {
        }

        #region 获取预约时间列表     
        /// <summary>
        /// 获取预约时间列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(List<Dictionary<string, List<Dictionary<string, string>>>>), 200)]
        [AllowAnonymous]
        public IActionResult Get()
        {
            List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
            DateTime today = DateTime.Now;
            for (int i = 0; i < 7; i++)
            {
                Dictionary<string, object> targetDay = new Dictionary<string, object>();
                List<Dictionary<string, object>> hourList = new List<Dictionary<string, object>>();
                DateTime targetDate = today.AddDays(i);
                int startHour = i == 0 ? today.Hour : 0;
                targetDay.Add("date", targetDate.Date);
                string dateTitle = string.Format("{0}{1}", targetDate.ToString("dddd", new CultureInfo("zh-CN")), targetDate.Date.ToString("MM-dd"));
                if (i == 0)
                {
                    dateTitle = string.Format("今天({0}){1}", targetDate.ToString("dddd", new CultureInfo("zh-CN")), targetDate.Date.ToString("MM-dd"));
                }
                targetDay.Add("date_title", dateTitle);
                for (int j = today.Minute > 30 ? startHour + 1 : startHour; j < 24; j++)
                {
                    Dictionary<string, object> hourDic = new Dictionary<string, object>();
                    hourDic.Add("hour", j);
                    hourDic.Add("hour_title", string.Format("{0:00}:00-{1:00}:00", j, j + 1));
                    hourList.Add(hourDic);
                }

                targetDay.Add("children", hourList);
                result.Add(targetDay);
            }
            return Ok(result);
        }
        #endregion
    }
}
